﻿///<reference path="jquery.js">

(function ($) {
    $.extend($.fn, {
        sorterMouse: function () {
            var trs = this;
            this.css("cursor", "pointer");
            return this.hover(function () {
                $(this).addClass("tr_hoverStyle");
            }, function () {
                $(this).removeClass("tr_hoverStyle");
            }
        ).click(function () {
            trs.removeClass("tr_hoverStyle").removeClass("tr_selectStyle");
            $(this).removeClass("tr_hoverStyle").addClass("tr_selectStyle");
        });
        },
        WaterMark: function (wAttr) {//水印效果
            var attr = wAttr ? wAttr : "watermark";
            $(this).focus(function () {
                if ($(this).val() == $(this).attr(attr)) $(this).removeClass("gray_input").val("");
            }).blur(function () { if ($(this).val() == "") $(this).addClass("gray_input").val($(this).attr(attr)); });
        },
        CheckAll: function (tContainer) {
            $(this).click(function () {
                if ($(this).attr("checked"))
                    tContainer.find(":checkbox").attr("checked", "checked");
                else
                    tContainer.find(":checked").removeAttr("checked");
            });
        },
        SuggestEx: function (handler, data, onSelect, mutipage, cdAttr, vlAttr) {
            $(this).Suggest(handler, data, function (data, selectedIndex, selectedItem) {
                onSelect(data, selectedIndex, selectedItem);
                $(this).attr(vlAttr, $(this).val());
            }, mutipage).change(function () {
                if ($(this).val() == $(this).attr(vlAttr)) return;
                $(this).attr(cdAttr, "");
            });
        },
        MgrShopSelect: function (appPath, shops, title) {
            if (shops && shops.length == 1) {
                $(this).val(shops[0].SHOP_NAME);
                $(this).attr("codes", shops[0].SHOP_CODE);
                return;
            }
            $(this).attr("value", "选择/修改");
            $(this).click((function () {
                return function () {
                    window.parent.pop(title || "选择店铺", appPath + '/shop/Shop_Selector.aspx', 710, 530, (function (tgt) {
                        return function (data) {
                            var codes = [], names = [];
                            $(data).each(function () {
                                codes.push(this.SHOP_CODE);
                                names.push(this.SHOP_NAME);
                            });
                            tgt.attr("codes", codes.join(","));
                            tgt.attr("title", names.join("、"));
                            tgt.attr("value", names.join("、"));
                            if (data == null || data.length == 0) tgt.attr("value", "选择/修改");
                        };
                    })($(this)));
                }
            })(appPath, title));
        },
        InitUniqueCode: function (vl) { $(this).val(vl).attr("state", "0").attr("srcvl", vl).attr("lstvl", vl); },
        UniqueCode: function (onCheck, bChkbtn) {
            $(this).InitUniqueCode("");
            $(this).change(function () {
                if ($(this).attr("srcvl") == $(this).val()) {
                    $(this).attr("state", "0");
                    return;
                }
                if ($(this).attr("lstvl") == $(this).val()) {
                    if ($(this).attr("state") == "-1") {
                        onCheck();
                        return;
                    }
                }
                onCheck();
            });
            if (bChkbtn) {
                var bchk = $('<input type="button" id="btnCheck" value="检测" class="btn_w_62" />');
                $(this).parent().append(bchk);
                var itm = $(this);
                bchk.click(function () {
                    if (itm.attr("state") == "0")
                        return;
                    itm.change();
                });
            }
        },
        OtherCbInput: function (vlAttr, nmAttr, bName, fldnmAttr) {
            $(this).click(function () {
                var curpp = $(this).parent().parent();
                if (curpp.find(":checkbox[fn='unchk']").size() > 0) curpp.find(":checkbox[fn='unchk']").removeAttr("checked");
                $(this).removeAttr("checked");
                var item = $("<span><input type=\"checkbox\" checked=\"checked\"/><input type=\"text\" class=\"input_style\" /></span>").insertBefore($(this).parent());
                var module = $(this).attr(fldnmAttr);
                item.find(":checkbox").click(function () {
                    var pp = $(this).parent().parent();
                    if (pp.find(":checked").size() == 0) pp.find(":checkbox[fn='unchk']").attr("checked", "checked");
                    if (!$(this).attr("checked")) $(this).parent().remove();
                });
                item.find(":text").keyup(function () {
                    try { $(this).prev(":checkbox").attr(nmAttr, $(this).val()).attr(vlAttr, "").val(""); } catch (e) { }
                }
			        ).verification({
			            isMust: true, rule: function (o) {
			                var rtn = { isSucceed: true, message: "" };
			                var obj = o.prev(":checkbox");
			                if (bName && $.FxNull(obj.attr(nmAttr), "") == "") {
			                    rtn.message = "请输入" + module + ".";
			                    rtn.isSucceed = false;
			                }
			                if (!bName && $.FxNull(obj.attr(vlAttr), "") == "") {
			                    rtn.message = "请输入" + module + ".";
			                    rtn.isSucceed = false;
			                }
			                return rtn;
			            }
			        }).focus();
            });
        },
        UnChkCbItems: function (tgFilter, ntgFilter, delFilter) {
            $(this).click(function () {
                var container = $(this).parent().parent();
                if ($(this).attr("checked")) {
                    container.find(":checked[" + ntgFilter + "]").removeAttr("checked");
                    if (delFilter && delFilter.length > 0) container.find(delFilter).remove();
                }
            });
            $(this).parent().parent().find(":checkbox[" + ntgFilter + "]").click(function () {
                var pt = $(this).parent().parent();
                if (pt.find(":checked[" + ntgFilter + "]").size() == 0)
                    pt.find(":checkbox[" + tgFilter + "]").attr("checked", "checked");
                else
                    pt.find(":checkbox[" + tgFilter + "]").removeAttr("checked");
            });
        },
        EnterSearch: function (tgEle) { $(this).keydown(function (e) { if (e.which - 0 == 13) { tgEle.click(); } }); },
        GetIdNoInfo: function (fSetBirth, fSetGender) {
            if (fSetBirth || fSetGender) {
                $(this).blur(function () {
                    var cvl = $.trim($.FxNull($(this).val(), ""));
                    if (cvl.length == 18 || cvl.length == 15) {
                        var rslt = validCardId(cvl);
                        if (rslt[0]) {
                            if (fSetBirth) fSetBirth($.FxNull(rslt[2], ""));
                            if (fSetGender) fSetGender($.FxNull(rslt[1], ""));
                        }
                    }
                });
            }
        },
        FxIE8Table: function (iRowHeight) {
            if ($.browser.msie && /^8\..*/.test($.FxNull($.browser.version, ""))) {
                if (!iRowHeight || !/^(([1-9])|(\d{2,}))$/.test(iRowHeight)) iRowHeight = 16;
                $(this).css("height", $(this).find("tr").size() * iRowHeight);
            }
        }
    }); // end of extend $.fn
})(jQuery);
jQuery.extend({
    FxNull: function (vl, dftvl) { return (vl != null && vl != undefined) ? vl : dftvl; },
    JoinVal: function (tArr, spliter) {
        if (!tArr) return null; var tpArr = [];
        $(tArr).each(function () { tpArr.push(this.val); });
        return tpArr.join(spliter ? spliter : "，");
    },
    DateCompare: function (dts, dte) {
        dts = $.trim($.FxNull(dts, ""));
        dte = $.trim($.FxNull(dte, ""));
        var dtsArr = dts.split(/[-\/\.]/, 3);
        var dteArr = dte.split(/[-\/\.]/, 3);
        var ts = new Date(dtsArr[0], (dtsArr[1] - 1) + "", dtsArr[2]);
        var te = new Date(dteArr[0], (dteArr[1] - 1) + "", dteArr[2]);
        var rslt = (ts - te);
        return rslt > 0 ? 1 : (rslt == 0 ? 0 : -1);
    },
    Scroll2Error: function (errIndex) {
        if (!errIndex) errIndex = 0;
        var errs = $(".alxv-failed,:text[message]");
        if (errIndex > (errs.size() - 1)) errIndex = 0;
        if (errs.size() > 0) $(document).scrollTop(errs.eq(errIndex).offset().top);
    },
    OracleByteLength: function (str) {
        return (str + "").replace(/[\u4e00-\u9fa5]/g, "---").length;
    },
    BuildCbInput: function (vlAttr, nmAttr, vl, nm, bName, module, tContainer) {
        var item = $("<span><input type=\"checkbox\" checked=\"checked\"/><input type=\"text\" class=\"input_style\" /></span>").insertBefore(tContainer.find("label:last-child"));
        item.find(":checkbox").click(function () {
            var pp = $(this).parent().parent();
            if (pp.find(":checked").size() == 0) pp.find(":checkbox[fn='unchk']").attr("checked", "checked");
            if (!$(this).attr("checked")) $(this).parent().remove();
        }).val($.FxNull(vl, "")).attr(vlAttr, $.FxNull(vl, "")).attr(nmAttr, $.FxNull(nm, ""));

        item.find(":text").change(function () { $(this).prev(":checkbox").attr(nmAttr, $(this).val()).attr(vlAttr, "").val(""); }).verification({
            isMust: true, rule: function (o) {
                var rtn = { isSucceed: true, message: "" };
                var obj = o.prev(":checkbox");
                if (bName && $.FxNull(obj.attr(nmAttr), "") == "") {
                    rtn.message = "请输入" + module + ".";
                    rtn.isSucceed = false;
                }
                if (!bName && $.FxNull(obj.attr(vlAttr), "") == "") {
                    rtn.message = "请输入" + module + ".";
                    rtn.isSucceed = false;
                }
                return rtn;
            }
        }).val(nm);
    },
    FillDataList: function (obj) {
        //{ Rows: [{a:"",IsH:true/false}], Command: [{Name:,Url:,IsLink:,Fn:,Attr:[]}],RowAttr:[{key,val}]}
        var tr = $("<tr></tr>"), opt;
        $(obj.Rows).each(function () {
            if (this.IsH) $("<td></td>").appendTo(tr).text($.FxNull(this.a, ""));
            else $("<td></td>").appendTo(tr).html($.FxNull(this.a, ""));
        });
        if (obj.RowAttr && obj.RowAttr.length > 0) {
            var cmd = $("<td class='opt'></td>").appendTo(tr);
            if (obj.Command && obj.Command.length > 0)
                $(obj.Command).each(function () {
                    if (this.IsLink) opt = $("<a href='" + this.Url + "'><span>" + this.Name + "</span></a>").appendTo(cmd);
                    else if (this.Btn) opt = $("<input type=\"button\" class=\"btn_w_62\" value=\"" + this.Name + "\"/>").appendTo(cmd).click(this.Fn);
                    else opt = $("<a href='javascript:'><span>" + this.Name + "</span></a>").appendTo(cmd).click(this.Fn);
                    if (this.Attr && this.Attr.length > 0) $(this.Attr).each(function () { opt.attr(this.key, this.val); });
                });
        }
        if (obj.RowAttr && obj.RowAttr.length > 0) $(obj.RowAttr).each(function () { tr.attr(this.key, this.val); });
        return tr;
    },
    IsScRle: function (roleCode) { roleCode = $.trim(roleCode); return (roleCode == "01" || roleCode == "02"); },
    IsDate: function (strDate) { return /^\d{4}(\/|-)([1][0-2]|[1-9]|0[1-9])(\/|-)([1-2][0-9]|3[0-1]|[1-9]|0[1-9])$/ig.test(strDate); },
    UnicodeLen: function (strLen) { return strLen.replace(/[\u2E80-\u9FFF]/ig, "---").length; }
});


//校验身份证号码
var Cardpowers = new Array("7", "9", "10", "5", "8", "4", "2", "1", "6", "3", "7", "9", "10", "5", "8", "4", "2");

var CardparityBit = new Array("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"); var sex = "male";    //校验身份证号码的主调用

function validCardId(_id) {
    var arrCard = new Array();
    arrCard[0] = false;
    if (_id == "") return arrCard;
    if (_id.length == 15) {
        arrCard = validId15(_id.toUpperCase());
    } else if (_id.length == 18) {
        arrCard = validId18(_id.toUpperCase());
    }

    return arrCard;
}




//校验18位的身份证号码
function validId18(_id) {
    var arr = new Array();
    arr[0] = false;
    arr[1] = "";
    arr[2] = "";
    _id = _id + "";

    var _num = _id.substr(0, 17);

    var _parityBit = _id.substr(17);

    var _power = 0;

    var year = _id.substr(6, 4);

    var month = _id.substr(10, 2);

    var day = _id.substr(12, 2);


    arr[2] = year + "-" + month + "-" + day;


    for (var i = 0; i < 17; i++) {            //校验每一位的合法性 
        if (_num.charAt(i) < '0' || _num.charAt(i) > '9') {

            return arr;

            break;

        } else {                //加权 
            _power += parseInt(_num.charAt(i)) * parseInt(Cardpowers[i]);                //设置性别 
            if (i == 16 && parseInt(_num.charAt(i)) % 2 == 0) {
                //女
                arr[1] = "2";


            } else {
                //男
                arr[1] = "1";

            }

        }

    }        //取模 
    var mod = parseInt(_power) % 11;

    if (CardparityBit[mod] == _parityBit) {
        arr[0] = true;
        return arr;

    }

    return arr;

}    //校验15位的身份证号码
function validId15(_id) {

    _id = _id + "";

    var arr = new Array();
    arr[0] = false;
    arr[1] = "";
    arr[2] = "";


    for (var i = 0; i < _id.length; i++) {            //校验每一位的合法性 
        if (_id.charAt(i) < '0' || _id.charAt(i) > '9') {

            return arr;

            break;

        }

    }

    var year = _id.substr(6, 2);

    var month = _id.substr(8, 2);

    var day = _id.substr(10, 2);

    arr[2] = "19" + year + "-" + month + "-" + day;

    var sexBit = _id.substr(14);        //校验年份位
    if (year < '01' || year > '90') return arr;        //校验月份
    if (month < '01' || month > '12') return arr;        //校验日
    if (day < '01' || day > '31') return arr;        //设置性别 
    if (sexBit % 2 == 0) {
        //女
        arr[1] = "2";

    } else {
        //男
        arr[1] = "1";

    }
    arr[0] = true;
    return arr;

}


function AddTable(divId, tableId, arr, colWidths, width) {
    var strWidth = "";
    if (width != "" || width != undefined) {
        strWidth = "width=" + width;
    }
    if ($("#" + tableId).length == 0) {

        var str = '<table id="' + tableId + '" class="tableStyle" ' + strWidth + '>' +
               '<thead>' +
               '<tr">';
        for (var i = 0; i < arr.length; i++) {
            str += '<td align="center" width=' + colWidths[i] + '><b>' + arr[i] + '</b></td>';
        }
        str += '<td align="center"><b>操作</b></td>';
        str += "</tr></thead><tbody></tbody></table>";

        $("#" + divId).append(str);
    }
    else {
        $("#" + tableId + ">tbody tr").remove();
    }
}

function AddRows(tableId, row, rowHdName, rowHdValue) {
    if (rowHdName.length != rowHdValue.length) {
        alert("数组维数不同.请确认")
        return;
    }

    var otable, otr, otd;
    otable = $("#" + tableId + ">tbody");

    //添加行
    otr = $('<tr></tr>').appendTo(otable);

    for (var i = 0; i < row.length; i++) {
        $('<td></td').appendTo(otr).text(row[i]);
    }

    //添加删除按钮
    otd = $('<td></td').appendTo(otr).html("<input type='button' name='btnDel' value='删除' />");

    for (var i = 0; i < rowHdName.length; i++) {
        $("<input type='hidden' name='" + rowHdName[i] + "'/>").appendTo(otd).val(rowHdValue[i]);
    }



}


function CheckRequired(oFrom) {
    var o = { isCheck: true, obj: undefined };
    $(oFrom).find("input[isSucceed],select[isSucceed]").each(function () {
        $(this).blur();
        if (($(this).attr("isSucceed") == "false" && $(this).attr("isMust") == "true") || ($(this).attr("isSucceed") == "false" && $(this).css("borderColor").toUpperCase() != "#B5B8C8" && $(this).attr("isMust") == "false")) {
            switch (this.type) {
                case "text":
                    $(this).css("borderColor", "red");

                    break;
                case "select-one":
                    $(this).css("borderColor", "red");
                    break;

            }
            if (o.obj == undefined) {
                o = { isCheck: false, obj: $(this) };
            }
        }
    });

    return o;
}


///验证控件
(function ($) {
    $.fn.extend({
        verification: function (f) {
            var options = {
                success: 'alxv-success',
                failed: 'alxv-failed',
                msg: 'alxv-msg',
                json: 'alxjs',
                inpSuccessColor: "#B5B8C8",
                inpFailColor: "red"
            };


            if ($(this) == undefined) {
                return this;
            }


            var jd = $(this);
            var o = f.rule(jd);
            var theThis = this;
            theThis.attr("isSucceed", "false");
            theThis.attr("message", o.message);
            theThis.attr("isMust", f.isMust);

            this.blur(function () {

                jd = $(this);
                theThis = this;
                o = f.rule(jd);

                //移除原来的提示信息
                $("#content div.hint").remove();
                if (!o.isSucceed) {
                    if (jd.val() == "" && !f.isMust)
                    { jd.css("borderColor", options.inpSuccessColor); }
                    else
                    { jd.css("borderColor", options.inpFailColor); }
                    jd.attr("isSucceed", "false");
                    jd.attr("message", o.message);
                }
                else {
                    jd.css("borderColor", options.inpSuccessColor);
                    jd.removeAttr("isSucceed");
                    jd.removeAttr("message");
                }
            }).focus(function () {
                jd = $(this);
                theThis = this;
                o = f.rule(jd);
                if (!o.isSucceed) {
                    if (jd.attr("message") != undefined && jd.css("borderColor") == options.inpFailColor) {
                        msg = '<div class="hint">' + jd.attr("message") + '<span class="hint-pointer"></span></div>';
                        $("#content").append(msg);

                        var imgWidth = 0;
                        if ($(jd).next("img").length == 1) {
                            imgWidth = imgWidth + $(jd).next("img").width();
                        }

                        if ($(jd).next("button").length == 1) {
                            imgWidth = imgWidth + $(jd).next("button").width();
                        }

                        var windowWidth = $("body").width();
                        var tempWidth = (jd.offset().left + jd.width() + 16 + imgWidth);
                        var thisWidth = $("#content div.hint").width() + jd.width();

                        if (windowWidth < (tempWidth + thisWidth)) {
                            tempWidth = jd.offset().left - thisWidth;
                            $(".hint-pointer", $("#content div.hint")).removeClass("hint-pointer").addClass("hint-pointer1");

                        }

                        $("#content div.hint").css({
                            'left': tempWidth + "px",
                            'top': (jd.offset().top) + "px",
                            'z-index': $.maxzIndex
                        });


                        //                        $("#content div.hint").css({ 'left': (jd.offset().left + jd.width() + 16 + imgWidth) + "px",
                        //                            'top': (jd.offset().top) + "px",
                        //                            'z-index': $.maxzIndex
                        //                        });
                        $("#content div.hint").show();

                    }
                }
            }).change(function () {
                jd = $(this);
                theThis = this;
                o = f.rule(jd);
            });

            if (this.val() != "") {
                jd = $(this);
                theThis = this;
                o = f.rule(jd);
            }

            return theThis;
        }
    });
})(jQuery);

function ShowWarn(msg) {
    alert(msg);
}


function isDate(dateStr) {
    var arr = dateStr.split("-")

    try {

        new Date(parseInt(arr[0], 10), parseInt(arr[1], 10), parseInt(arr[2], 10));
        return true;

    } catch (e) {
        return false;
    }


}

String.prototype.strIsData = function () {
    var datePat = /^(\d{4})(\-)(\d{1,2})(\-)(\d{1,2})$/;
    var matchArray = dateStr.match(datePat);
    if (matchArray == null) return false;
    var month = matchArray[3];
    var day = matchArray[5];
    var year = matchArray[1];
    if (month < 1 || month > 12) return false;
    if (day < 1 || day > 31) return false;
    if ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) return false;
    if (month == 2) {
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day == 29 && !isleap)) return false;
    }
    return true;
}


function StrToDate(str) {

    var arr = str.split("-")

    try {

        return new Date(parseInt(arr[0], 10), parseInt(arr[1], 10), parseInt(arr[2], 10));

    } catch (e) {
        return new Date(4000, 12, 31);
    }
}


Number.prototype.toFixed = function (d) {

    var s = this + ""; if (!d) d = 0;

    if (s.indexOf(".") == -1) s += "."; s += new Array(d + 1).join("0");

    if (new RegExp("^(-|\\+)?(\\d+(\\.\\d{0," + (d + 1) + "})?)\\d*$").test(s)) {

        var s = "0" + RegExp.$2, pm = RegExp.$1, a = RegExp.$3.length, b = true;

        if (a == d + 2) {
            a = s.match(/\d/g); if (parseInt(a[a.length - 1]) > 4) {

                for (var i = a.length - 2; i >= 0; i--) {
                    a[i] = parseInt(a[i]) + 1;

                    if (a[i] == 10) { a[i] = 0; b = i != 1; } else break;
                }

            }

            s = a.join("").replace(new RegExp("(\\d+)(\\d{" + d + "})\\d$"), "$1.$2");

        } if (b) s = s.substr(1); return (pm + s).replace(/\.$/, "");
    } return this + "";

};



//页面封装初始化事件,及加载数据
function HrPage(eventFn, initFn) {
    this.PageEvent = eventFn;
    this.PageInit = initFn;
    this.Bind = function () {
        if (this.PageEvent != undefined) this.PageEvent();
        if (this.PageInit != undefined) this.PageInit();
    }
    this.Bind();
}


(function ($) {
    //$(":input:text:eq(0)").focus();  //防止弹出层失去焦点
    $(":text,input:checked,select").eq(0).focus();
    $.fn.extend({
        vPersonEdit: function (f) {
            var options = {
                success: 'alxv-success',
                failed: 'alxv-failed',
                msg: 'alxv-msg',
                json: 'alxjs',
                inpFailClass: "error_bg"
            };


            if ($(this) == undefined) {
                return this;
            }


            var jd = $(this);
            var o = f.rule(jd);
            var theThis = this;
            theThis.attr("isSucceed", "false");
            theThis.attr("message", o.message);
            theThis.attr("isMust", f.isMust);

            this.blur(function () {

                jd = $(this);
                theThis = this;
                o = f.rule(jd);

                //移除原来的提示信息
                $("body div.hint").remove();
                if (!o.isSucceed) {
                    if (jd.val() == "" && !f.isMust)
                    { jd.removeClass(options.inpFailClass); }
                    else
                    { jd.addClass(options.inpFailClass); }
                    jd.attr("isSucceed", "false");
                    jd.attr("message", o.message);
                }
                else {
                    jd.removeClass(options.inpFailClass);
                    jd.removeAttr("isSucceed");
                    jd.removeAttr("message");
                }
            }).focus(function () {
                jd = $(this);

                theThis = this;
                o = f.rule(jd);
                if (!o.isSucceed) {
                    if (jd.attr("message") != undefined && jd.hasClass(options.inpFailClass)) {
                        msg = '<div class="hint">' + jd.attr("message") + '<span class="hint-pointer"></span></div>';
                        $("body").append(msg);

                        var imgWidth = 0;
                        if ($(jd).next("img").length == 1) {
                            imgWidth = imgWidth + $(jd).next("img").width();
                        }

                        if ($(jd).next("button").length == 1) {
                            imgWidth = imgWidth + $(jd).next("button").width();
                        }

                        var windowWidth = $("body").width();
                        var tempWidth = (jd.offset().left + jd.width() + 16 + imgWidth);
                        var thisWidth = $("div.hint").width() + 52;

                        if (windowWidth < (tempWidth + thisWidth)) {
                            tempWidth = jd.offset().left - thisWidth;
                            $(".hint-pointer", $("div.hint")).removeClass("hint-pointer").addClass("hint-pointer1");

                        }

                        $("body div.hint").css({
                            'left': tempWidth + "px",
                            'top': (jd.offset().top) + "px",
                            'z-index': $.maxzIndex
                        });


                        $("body div.hint").show();

                    }
                }
            }).change(function () {
                jd = $(this);
                theThis = this;
                o = f.rule(jd);
            });

            if (this.val() != "") {
                jd = $(this);
                theThis = this;
                o = f.rule(jd);
            }

            return theThis;
        }
    });
})(jQuery);

//回车即搜索
function enterHandler(event, btnname) {
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (keyCode == 13) {
        $("#" + btnname).click();
    }
}

//比较日期函数
function dateCompare(dateStr1, dateStr2) {
    var dateArr1 = dateStr1.split("-");
    var dateArr2 = dateStr2.split("-");

    var startDate = new Date(dateArr1[0], dateArr1[1], dateArr1[2]);
    var endDate = new Date(dateArr2[0], dateArr2[1], dateArr2[2]);

    if (startDate <= endDate)
        return true;
    else
        return false;
}

//检查日期有效性
//日期格式：YYYY-MM-DD
function validateDate(dateStr) {
    var monthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    var dateArr = dateStr.split("-");
    if (dateArr.length != 3) return false;
    var yyyy = dateArr[0];
    var mm = dateArr[1];
    var dd = dateArr[2];
    if (yyyy.length != 4) return false;
    if (yyyy < 1754) return false;
    if (!isInteger(yyyy) || !isInteger(mm) || !isInteger(dd)) return false;
    if (((yyyy % 4 == 0) && (yyyy % 100 != 0)) || (yyyy % 400 == 0)) monthDays[1] = 29;
    if (mm < 1 || mm > 12 || dd > monthDays[mm - 1] || dd < 1) return false;
    return true;
}

function isInteger(inputVal) {
    if (inputVal.indexOf(" ") != -1) return false;
    if ((inputVal.indexOf('.') != -1) || (isNaN(inputVal))) return false;
    return true;
}
function DTemplate() {
    /*
    依据模版以及数据项生成相应的文本（html Encode）    
    模版字段：${数据中成员}
    */
    var tmpNode = $("<div/>");
    this.htmlEncode = function (data) { return tmpNode.text(data).html(); };
    var encode = this.htmlEncode;
    this.Run = function (tmpl, item, nEncode) {
        return tmpl.replace(/\$\{([^{}]+)\}/g, function (match, key) {
            var keys = key.split(".");
            var obj = item;
            for (i = 0; i < keys.length; i++) {
                if (keys[i] in obj) { obj = obj[keys[i]]; continue; }
                return match;
            }
            return (obj == null || obj == undefined) ? "" : (nEncode ? IfDate2String(obj) : encode(IfDate2String(obj)));
        });
    };
    var template = this.Run;
    return function (tmpl, dataArr, nEncode) {
        var strs = [];
        if (dataArr == null || dataArr == undefined) return "";
        dataArr = $.isArray(dataArr) ? dataArr : [dataArr];
        if (dataArr.length == 0) return "";
        $(dataArr).each(function () { strs.push(template(tmpl, this, nEncode)); });
        return strs.join("");
    };
}
function IfDate2String(date) { return date.constructor == Date ? date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() : date.toString(); }


function addCount() {
    $("#lblRecordCount").text(parseInt($("#lblRecordCount").text()) + 1);
}

function reduceCount() {
    $("#lblRecordCount").text(parseInt($("#lblRecordCount").text()) -1);
}